Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es6-mapify

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-mapify

Convert JS objects to ES6 Maps and vice versa

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25K
decreased by-11.08%
Maintainers
1
Weekly downloads
 
Created
Source

ES6-Mapify

Convert JS Objects to ES6 Maps and vice versa.

ES6 Map objects are really nice for iteration, but they're not so nice for directly referencing properties, the way JS Objects are. This is a nice way to convert back and forth. First, simply use npm to include es6-mapify in your project's dependencies:

npm install -S es6-mapify

Now you can import it and use it like so:

import { mapify } from 'es6-mapify';

// converts basic objects
let myObj = {foo: 'bar'};
let myMap = mapify(myObj);
myMap.get('foo'); // 'bar'

// doesn't do anything to non-objects
mapify('foo'); // 'foo';
mapify(null);  // null

// is smart about objects nested inside arrays and other objects
let arrMap = mapify([1, {foo: 'bar'}, 3]);
arrMap[2];            // 3
arrMap[1].get('foo'); // 'bar'

let myMap = mapify({foo: {bar: 'baz'}});
myMap.get('foo').get('bar'); // 'baz';

Of course, you might want to go the other direction too! If you have a Map and want the corresponding basic JS object, just use demapify:

import { demapify } from 'mapify';

// converts basic maps
let myMap = new Map();
myMap.set('foo', 'bar');
demapify(myMap); // {foo: 'bar'}

// doesn't do anything to non-objects
demapify(2); // 2

// is smart about nested Maps (and Maps in arrays)
let myMap = new Map()
  , myMap2 = new Map();
myMap.set('foo', 'bar');
myMap2.set('baz', 'quux');
myMap.set('inception', myMap2);
demapify(myMap); // {foo: 'bar', inception: {baz: 'quux'}}

FAQs

Package last updated on 16 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc